﻿using AutoRetailsDLL.Workers.PinDuoDuo;
using AutoRetailsEXE;
using CefSharp;
using CefSharp.WinForms;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;


namespace AutoRetailsDLL.Workers.JingDong
{
    public class TEMUWorker : WorkersBase
    {
        private string web_url = "https://seller.kuajingmaihuo.com/goods/product-create/category";
        private string web_login_url = "https://seller.kuajingmaihuo.com";//"https://www.baidu.com/?tn=62095104_19_oem_dg";//"https://mms.pinduoduo.com/home/";
        private TEMUAddGoodModel_In param_in = null;
        private static string _count=string.Empty;
        private static string _password = string.Empty;
        private bool Is判断Login状态=false;
        //不可直接用
        private static bool Is登录 = false;
        public static TEMUWorker Instance = new TEMUWorker();

        public void InitPinDuoDuoAsync()
        {
            LogHelper.WriteLog($"InitPinDuoDuoAsync执行");
            chromePage.Show();
            GetChromiumWebBrowser().LoadUrl(web_url);
            WaitWebBrowserAsync(2000);
            WaitWebBrowserLoadingAsync();
            //设置上传文件事件
            SetUploadFileDialogHandler();
            GetChromiumWebBrowser().AddressChanged += PinDuoDuoWorker_AddressChanged;
            //await Login();
        }
        
        private void PinDuoDuoWorker_AddressChanged(object sender, AddressChangedEventArgs e)
        {
            var chromiumWebBrowser = (ChromiumWebBrowser)sender;
            var newAddress = chromiumWebBrowser.Address;
            if (Is判断Login状态&& newAddress.Contains("login"))
            {
                Is登录 = false;
            }
            Is登录 = true;
            // 在这里处理新的地址
            //System.Diagnostics.Debug.WriteLine($"New Address: {newAddress}");
        }
        
        public async Task<WorkResult> Login(string count,string password)
        {
            try {
                LogHelper.WriteLog($"开始登陆：{count}，{password}");
                InitPinDuoDuoAsync();
                执行必备JS();
                点击元素_输入(JavaScriptString.TEMU_账号输入框JS, count,500);
                点击元素_输入(JavaScriptString.TEMU_密码输入框JS, password, 500);
                点击元素_输入(JavaScriptString.TEMU_同意隐私政策JS, password, 500);
                点击元素_左键(JavaScriptString.TEMU_登录按钮JS, 500);
                for (int i = 0; i < 5; i++)
                {
                    if (IsLogin2())
                    {
                        result=WorkResult.WorkSuccess();
                        return result;
                    }
                    else
                    {
                        WaitWebBrowserAsync(1000);
                    }
                }
                result=WorkResult.WorkFailed();
                return result;
            } 
            catch (Exception ee)
            {
                LogHelper.WriteLog($"Login发生异常", ee);
                return WorkResult.WorkFailed();
            }
                     
        }
        public async Task<WorkResult> AddGood(string json,string configJson) 
        {
            result = new WorkResult();
            try
            {
                LogHelper.WriteLog($"AddGood入参：{json}");
                LogHelper.WriteLog($"AddGood配置入参：{configJson}");
                SetConfig(configJson);
                TEMUAddGoodModel_In pinDuoDuoAddGoodModel_In = JsonConvert.DeserializeObject<TEMUAddGoodModel_In>(json);
                param_in = pinDuoDuoAddGoodModel_In;
                AddGood();
                LogHelper.WriteLog($"任务结束出参：{JsonConvert.SerializeObject(result)}");
                return result;
            }
            catch (Exception ee)
            {
                LogHelper.WriteLog($"AddGood异常",ee);
                return WorkResult.WorkFailed($"AddGood异常:{ee}");
            }
           
        }
        public async Task<WorkResult> AddGood(TEMUAddGoodModel_In pinDuoDuoAddGoodModel_In, WorkerConfig workerConfig)
        {
            result = null;
            try
            {
                LogHelper.WriteLog($"AddGood入参：{JsonConvert.SerializeObject(pinDuoDuoAddGoodModel_In)}");
                LogHelper.WriteLog($"AddGood配置入参：{JsonConvert.SerializeObject(pinDuoDuoAddGoodModel_In)}");
                SetConfig(workerConfig);
                param_in = pinDuoDuoAddGoodModel_In;
                AddGood();
                LogHelper.WriteLog($"任务结束出参：{JsonConvert.SerializeObject(result)}");
                return result;
            }
            catch (Exception ee)
            {
                LogHelper.WriteLog($"AddGood异常", ee);
                return WorkResult.WorkFailed($"AddGood异常:{ee}");
            }

        }
        /// <summary>
        /// 通过刷新页面判断，更准确
        /// </summary>
        /// <returns></returns>
        public bool IsLogin()
        {
            Is判断Login状态=true;
            GetChromiumWebBrowser().LoadUrl(web_url);
            WaitWebBrowserLoadingAsync();
            WaitWebBrowserAsync(5000);
            LogHelper.WriteLog($"登录验证：{Is登录}");
            Is判断Login状态 = false;
            return Is登录;
        }
        /// <summary>
        /// 通过判断页面判断
        /// </summary>
        /// <returns></returns>
        public bool IsLogin2()
        {
            bool islogin=false;
            if (!GetChromiumWebBrowser().Address.Contains("login"))
            {
                islogin =true;
            }
            LogHelper.WriteLog($"登录验证：{islogin}");
            return islogin;
        }
        public void SetParam(TEMUAddGoodModel_In pinDuoDuoAddGoodModel_In)
        {
            param_in = pinDuoDuoAddGoodModel_In;
        }
        public WorkResult AddGood() 
        {
            bool login_result = IsLogin();
            if (!login_result)
            {               
                result = WorkResult.WorkFailed("请先登录");
                return result;
            }
            checkParamIn();

            执行必备JS();
            选择品类();
            执行必备JS();
            if (endTime<DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            bool 上传商品轮播图_Result = 上传商品轮播图();
            if (!上传商品轮播图_Result)
            {
                return result;
            }
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            bool 属性填写_Result= 填写商品属性();
            if (!属性填写_Result)
            {
                return result;
            }
            商品包装信息();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            商品规格();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            bool 敏感属性_Result = 填写敏感属性();
            if (!敏感属性_Result)
            {
                return result;
            }
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            
            //上传详情图();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }

            商品规格2();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            //售后物流及其他();
            if (endTime < DateTime.Now)
            {
                result = WorkResult.WorkFailed("任务超时");
                return result;
            }
            提交或保存();
            判断发布商品最终成功();
            return result;
        }
        public async Task<WorkResult> TestAddGood() 
        {
            //执行必备JS();
            //选择品类();
            //上传轮播图();
            填写商品属性();
            //上传详情图();
            //上传白底图();
            //规格与库存();
            //规格与库存2();
            //服务与承诺();
            //提交或保存();
            //判断发布商品最终成功();
            return result;
        }
        private string checkParamIn() 
        {
            return string.Empty;
        }
        public void 选择品类() 
        {
            LogHelper.WriteLog($"进入选择品类模块");
            
            LogHelper.WriteLog($"普通选择品类");
            点击元素_JS(JavaScriptString.TEMU_手机通讯JS, wordWaitTime);
            点击元素_JS(JavaScriptString.TEMU_手机配件JS, wordWaitTime);
            点击元素_JS(JavaScriptString.TEMU_手机壳保护套JS, wordWaitTime);
            点击元素_左键(JavaScriptString.TEMU_发布该类商品_按钮JS, listClickWaitTime);
            WaitWebBrowserAsync(5000);
            result = WorkResult.WorkSuccess(); 
        }
        
        private bool 上传商品轮播图()
        {            
            LogHelper.WriteLog($"进入上传轮播图模块");
            string ele = $@"getElementByText('div','批量上传')";
            设置元素居中2(ele);
            List<string> file_path_list = param_in.materialFile.FirstOrDefault(n => n.materialType== "master").specList.Select(n=>n.imageName).ToList();// new List<string> { @"E:\谷歌下载\1.jpeg", @"E:\谷歌下载\2.jpeg", @"E:\谷歌下载\3.jpeg" };
            string 开始上传按钮js = @"document.getElementById('noCostumeCarouselImgsI18n.common').getElementsByClassName('upload-trigger_txt__1ld83')[0]";
            点击元素_左键(开始上传按钮js, wordWaitTime);
            return 上传图片(file_path_list);
        }
        private void 商品包装信息()
        {
            LogHelper.WriteLog($"进入商品包装信息模块");
            string ele = $@"document.getElementById('outPackage.urls').getElementsByTagName('input')[0]";
            设置元素居中2(ele);
            List<string> file_path_list = param_in.materialFile.FirstOrDefault(n => n.materialType == "master").specList.Select(n => n.imageName).ToList();// new List<string> { @"E:\谷歌下载\1.jpeg", @"E:\谷歌下载\2.jpeg", @"E:\谷歌下载\3.jpeg" };
            SetUploadFilePath(file_path_list);
            点击屏幕();
            点击元素_JS(ele,wordWaitTime);
            result = WorkResult.WorkSuccess();
        }


        public bool 填写商品属性()
        {
            LogHelper.WriteLog($"进入填写商品属性模块");
            bool check_result=true;
            执行必备JS();

            //填写标题
            LogHelper.WriteLog($"填写标题");
            设置元素居中2(JavaScriptString.TEMU_标题输入框JS);
            点击元素_左键(JavaScriptString.TEMU_标题输入框JS,wordWaitTime);
            键盘输入(param_in.onlineGoodsTitle,wordWaitTime);
            //填写商品生产地（国家）
            LogHelper.WriteLog($"填写商品生产地（国家）");
            check_result = 填写内容并选取("productOriginCode", param_in.MadeInCountry);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"商品生产地（国家）：{param_in.MadeInCountry}未找到");
                return false;
            }
            //填写商品生产地（省份）
            LogHelper.WriteLog($"填写商品生产地（省份）");
            check_result = 填写内容并选取("productOriginProvinceCode",param_in.MadeInProvince);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"商品生产地（省份）：{param_in.MadeInProvince}未找到");
                return false;
            }
            //主要材质
            LogHelper.WriteLog($"填写主要材质");
            check_result = 填写内容并选取_模糊("productProperties[1440]",  param_in.goodsTexture);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"主要材质：{param_in.goodsTexture}未找到");
                return false;
            }
            //填写功能特点
            LogHelper.WriteLog($"填写功能特点");
            check_result = 填写内容并选取_模糊("productProperties[1324]", param_in.function);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"功能特点：{param_in.function}未找到");
                return false;
            }

            //填写流行元素
            LogHelper.WriteLog($"填写流行元素");
            check_result = 填写内容并选取_模糊("productProperties[1093]", param_in.fashionElement);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"流行元素：{param_in.fashionElement}未找到");
                return false;
            }

            //填写品牌名
            LogHelper.WriteLog($"填写品牌名");
            if (!string.IsNullOrEmpty(param_in.brand))
            {
                check_result = 填写内容并选取_模糊("productProperties[1960]", param_in.brand);
                if (!check_result)
                {
                    result = WorkResult.WorkFailed($"品牌名：{param_in.brand}未找到");
                    return false;
                }
            }
           
            //填写是否带支架
            LogHelper.WriteLog($"填写是否带支架");
            check_result = 填写内容并选取_模糊("productProperties[6580]", param_in.haveBracket);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"是否带支架：{param_in.haveBracket}未找到");
                return false;
            }
            //填写是否带镜头保护
            LogHelper.WriteLog($"填写是否带镜头保护");
            check_result = 填写内容并选取_模糊("productProperties[6579]", param_in.haveCameraProtection);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"是否带镜头保护：{param_in.haveCameraProtection}未找到");
                return false;
            }
            //填写壳体工艺
            LogHelper.WriteLog($"填写壳体工艺");
            check_result = 填写内容并选取_模糊("productProperties[6956]", param_in.shellProcess);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"壳体工艺：{param_in.shellProcess}未找到");
                return false;
            }
            //填写印花工艺
            LogHelper.WriteLog($"填写印花工艺");
            check_result = 填写内容并选取_模糊("productProperties[6957]", param_in.printingProcess);
            if (!check_result)
            {
                result = WorkResult.WorkFailed($"印花工艺：{param_in.printingProcess}未找到");
                return false;
            }           
            result = WorkResult.WorkSuccess();
            return true;
        }
        public bool 填写敏感属性()
        {
            LogHelper.WriteLog($"进入填写商品属性模块");
            //填写敏感属性是否下拉框
            LogHelper.WriteLog($"填写商品生产地（国家）");
            填写内容并选取("sensitiveAttr", "否");
            //填写最长边
            LogHelper.WriteLog($"填写最长边");
            设置元素居中(JavaScriptString.TEMU_最长边输入框JS);
            点击元素_输入(JavaScriptString.TEMU_最长边输入框JS, param_in.longestSide, wordWaitTime);
            //填写次长边
            LogHelper.WriteLog($"填写次长边");
            设置元素居中(JavaScriptString.TEMU_次长边输入框JS);
            点击元素_输入(JavaScriptString.TEMU_次长边输入框JS, param_in.secondLongestSide, wordWaitTime);
            //填写最长边
            LogHelper.WriteLog($"填写最短边");
            设置元素居中(JavaScriptString.TEMU_最短边输入框JS);
            点击元素_输入(JavaScriptString.TEMU_最短边输入框JS, param_in.shortestSide, wordWaitTime);
            //填写最长边
            LogHelper.WriteLog($"填写重量");
            设置元素居中(JavaScriptString.TEMU_重量输入框JS);
            点击元素_输入(JavaScriptString.TEMU_重量输入框JS, param_in.weight, wordWaitTime);
            //确认批量填写
            点击元素_左键(JavaScriptString.TEMU_批量填写确认按钮JS, wordWaitTime);
            result = WorkResult.WorkSuccess();
            return true;
        }
        private void 上传详情图()
        {
            LogHelper.WriteLog($"上传详情图");
            设置元素居中2(JavaScriptString.京东_详情图上传JS);
            List<string> file_path_list = param_in.materialFile.FirstOrDefault(n => n.materialType == "detail").specList.Select(n => n.imageName).ToList();//new List<string> { @"E:\谷歌下载\1.jpeg", @"E:\谷歌下载\2.jpeg", @"E:\谷歌下载\3.jpeg" };
            //SetUploadFilePath(file_path_list);
            WaitWebBrowserAsync(1000);
            点击元素_左键(JavaScriptString.京东_详情图上传JS, 2000);
            上传图片(file_path_list);
            result= WorkResult.WorkSuccess();
        }

     
        private void 规格与库存_ss()
        {
            LogHelper.WriteLog($"规格与库存");
            ExecuteScriptAndWaitAsync(JavaScriptString.拼多多_点击添加规格类型JS, 1000);
            string 点击并选择规格1js = @"document.getElementsByClassName(""goods-spec-row"")[0].getElementsByClassName(""IPT_input_5-126-0"")[0].click();
            getElementByText('li','{0}').click()";
            string 点击并选择规格2js = @"document.getElementsByClassName(""goods-spec-row"")[1].getElementsByClassName(""IPT_input_5-126-0"")[0].click();
            getElementByText('li','{0}').click()";
            string 输入规格1js= @"var ele= document.getElementsByClassName(""spec-input"")[{0}].getElementsByTagName(""input"")[0];setInputValue(ele,'{1}')";
            string 输入规格2js = @"var ele= document.getElementsByClassName(""spec-input"")[{0}].getElementsByTagName(""input"")[0];setInputValue(ele,'{1}')";
            string[] strings = param_in.specifications.Split('-');
            int input_index = 0;
            if (strings.Count()>0)
            {
                string js= string.Format(点击并选择规格1js, strings[0]);
                ExecuteScriptAndWaitAsync(js, wordWaitTime);
                for (int i = 0; i < param_in.spec1.Count; i++)
                {
                    string js2 = string.Format(输入规格1js, input_index, param_in.spec1[i]);
                    ExecuteScriptAndWaitAsync(js2, wordWaitTime);
                    点击屏幕();
                    input_index++;
                }               
            }
            if (strings.Count() > 1)
            {
                ExecuteScriptAndWaitAsync(JavaScriptString.拼多多_点击添加规格类型JS, 1000);
                string js = string.Format(点击并选择规格2js, strings[1]);
                ExecuteScriptAndWaitAsync(js, wordWaitTime);
                input_index++;
                for (int i = 0; i < param_in.spec2.Count; i++)
                {
                    string js2 = string.Format(输入规格2js, input_index, param_in.spec2[i]);
                    ExecuteScriptAndWaitAsync(js2, wordWaitTime);
                    点击屏幕();
                    input_index++;
                }
            }
            result = WorkResult.WorkSuccess();
        }
        private void 退出当前账号() 
        {
            点击元素_左键(JavaScriptString.拼多多_店铺信息按钮JS, 1000);
            点击元素_左键(JavaScriptString.拼多多_退出当前账号JS, 1000);
        }
        private string 获取用户名()
        {
            string js = @"(function(){
               return document.getElementsByClassName('user-name-text')[0].textContent
        })() ";
            string result = EvaluateScriptAsync(js);
            return result;
        }
        private bool 商品规格()
        {
            LogHelper.WriteLog($"商品规格");
            for (int i = 0; i < param_in.spec1.Count; i++)
            {
                string 手机型号输入框js= $@"document.getElementById('minorSpecList[0][{i}]').getElementsByTagName('input')[0];";
                设置元素居中2(手机型号输入框js);
                bool 填写result= 填写内容并选取_DIV2(手机型号输入框js, param_in.spec1[i]);
                if (!填写result)
                {
                    result= WorkResult.WorkFailed($"商品规格：{param_in.spec1[i]}未找到");
                }
                if (i+1< param_in.spec1.Count)
                {
                    string 添加按钮js = $@"getElementByTextAll('a','+ 添加')[0]";
                    点击元素_JS(添加按钮js, 2000);
                }

            }
            for (int i = 0; i < param_in.spec2.Count; i++)
            {
                string 颜色输入框js = $@"document.getElementById('minorSpecList[1][{i}]').getElementsByTagName('input')[0];";
                设置元素居中2(颜色输入框js);
                bool 填写result = 填写内容并选取_DIV2(颜色输入框js, param_in.spec2[i]);
                if (!填写result)
                {
                    result = WorkResult.WorkFailed($"商品规格：{param_in.spec2[i]}未找到");
                }
                if (i + 1 < param_in.spec2.Count)
                {
                    string 添加按钮js = $@"getElementByTextAll('a','+ 添加')[1]";
                    点击元素_JS(添加按钮js, 2000);
                }
            }                     
            result = WorkResult.WorkSuccess();
            return true;
        }

        private bool 商品规格2() 
        {
            LogHelper.WriteLog($"销售属性2");
            //找到规格表格元素
            string 声明speclist变量js = @"var speclistele=document.getElementsByClassName('performance-table_performanceTable__37JTX')[1].getElementsByTagName('tr')";
            ExecuteScriptAndWaitAsync(声明speclist变量js, 100);

            string 设置speclist变量js = @"var specinput=speclistele[{0}].getElementsByTagName('input')[{1}];setInputValue(specinput,'{2}');";
            foreach (Materialfile item in param_in.materialFile)
            {
                if (item.materialType=="sku")
                {
                    for (int i = 0; i < item.specList.Count; i++)
                    {
                        //申报价格
                        string js = string.Format(设置speclist变量js, i, 0, item.specList[i].price);
                        ExecuteScriptAndWaitAsync(js, wordWaitTime);
                        //上传图片
                        string file_upload_js = $@"speclistele[{i}].getElementsByClassName('upload-trigger_txt__1ld83')[0]";
                        设置元素居中2(file_upload_js);
                        点击元素_左键(file_upload_js,wordWaitTime);
                        bool result= 上传图片(new List<string>() { item.specList[i].imageName });
                        if (!result)
                        {                            
                            return false;
                        }
                        //SKU分类
                        string js2 = @$"speclistele[{i}].getElementsByTagName('input')[1]";
                        填写内容并选取_模糊2(js2, "单品");
                        //建议零售价
                        string js3 = string.Format(设置speclist变量js, i, 4, item.specList[i].singlePrice);
                        ExecuteScriptAndWaitAsync(js3, wordWaitTime);
                        //建议零售价单位
                        string js4 = @$"speclistele[{i}].getElementsByTagName('input')[5]";
                        填写内容并选取_模糊2(js4, item.specList[i].priceUnit);
                    }
                }
            }
           
            result = WorkResult.WorkSuccess();
            return true;
        }
        private bool 上传图片(List<string> img_path)
        {
            LogHelper.WriteLog($"进入上传图片模块");
            SetUploadFilePath(img_path);
            点击屏幕();
            WaitWebBrowserAsync(200);
            点击元素_左键(JavaScriptString.TEMU_本地上传按钮JS, pictureWaitTime);
            if (判断是否重复上传())
            {
                result = WorkResult.WorkFailed($"重复上传图片：{JsonConvert.SerializeObject(img_path)}");
                return false;
            }            
            等待上传执行完毕(img_path);
            选择上传的图片(img_path);
            点击元素_左键(JavaScriptString.TEMU_确认上传完毕按钮JS, 1000);
            result = WorkResult.WorkSuccess();
            return true;
        }
        private void 售后物流及其他() 
        {
            LogHelper.WriteLog($"售后物流及其他");
            string js = string.Empty;
            设置元素居中2(JavaScriptString.京东_无理由退货按钮JS);
            if (param_in.supply7DayReturn==1)
            {
                填写内容并选取_Class("rcd-form-item is-required common-form-item", 0, "支持7天无理由退货");

            }           
            result = WorkResult.WorkSuccess();
        }
        private void 提交或保存() 
        {
            LogHelper.WriteLog($"提交或保存");
            点击元素_左键(JavaScriptString.TEMU_同意协议勾选按钮JS, wordWaitTime);
            if (param_in.isDraft == 1)
            {
                LogHelper.WriteLog($"提交草稿");
                设置元素居中(JavaScriptString.TEMU_保存为草稿JS);
                点击元素_左键(JavaScriptString.TEMU_保存为草稿JS, wordWaitTime);
            }
            else 
            {
                LogHelper.WriteLog($"正式提交");
                设置元素居中(JavaScriptString.TEMU_提交并上架JS);
                点击元素_左键(JavaScriptString.TEMU_提交并上架JS, wordWaitTime);
            }

            result = WorkResult.WorkSuccess();
        }
        private void 判断发布商品最终成功() 
        {
            for (int i = 0; i < 10; i++)
            {
                string result_res = EvaluateScriptAsync(JavaScriptString.拼多多_判断提交结束JS);
                LogHelper.WriteLog($"正式提交结果判断：{result_res}");
                if (result_res == "True")
                {
                    var uri = new Uri(GetChromiumWebBrowser().Address);
                    NameValueCollection collection = HttpUtility.ParseQueryString(uri.Query);
                    result = WorkResult.WorkSuccess(collection["goods_id"]);
                    return;
                }
                WaitWebBrowserAsync(1000);
            }
            result = WorkResult.WorkFailed("判断提交是否成功超时");
        }
        private bool Is快捷选择品类按钮()
        {
            string result = EvaluateScriptAsync(JavaScriptString.拼多多_获取是否有快捷品类JS);
            if (result == "True")
            {
                return true;
            }
            return false;
        }
        private bool Is快捷选择品类是否被点击按钮()
        {
            string result = EvaluateScriptAsync(JavaScriptString.拼多多_快捷品类是否被点击JS);
            if (result == "True")
            {
                return true;
            }
            return false;
        }

        private bool 填写内容并选取(string id, string content)
        {
            string js_element = @"document.getElementById('{0}').getElementsByTagName('input')[0];";
            string js = string.Format(js_element, id);
            点击元素_输入(js, content, 1000);            
            if (Is选项存在(content))
            {
                string js_select = @"getElementByText('li','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_JS(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }
        private bool 填写内容并选取2(string ele_js, string content)
        {            
            点击元素_左键(ele_js,500);
            if (Is选项存在(content))
            {
                string js_select = @"getElementByText('li','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_JS(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }
        private bool 填写内容并选取_DIV(string id, string content)
        {
            string js_element = @"document.getElementById('{0}').getElementsByTagName('input')[0];";
            string js = string.Format(js_element, id);
            点击元素_输入(js, content, 1000);
            if (Is选项存在_DIV(content))
            {
                string js_select = @"getElementByText('div','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_JS(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }
        private bool 填写内容并选取_DIV2(string ele_js, string content)
        {
            点击元素_输入(ele_js, content, 1000);
            if (Is选项存在_DIV(content))
            {
                string js_select = @"getElementByText('div','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_JS(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }
        private bool 填写内容并选取_模糊(string id, string content)
        {
            string js_element = @"document.getElementById('{0}').getElementsByTagName('input')[0];";
            string js = string.Format(js_element, id);
            点击元素_输入(js, content, 1000);
            if (Is选项存在_模糊(content))
            {
                string js_select = @"getElementByText2('li','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_JS(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }
        private bool 填写内容并选取_模糊2(string js_ele, string content)
        {
            点击元素_输入(js_ele, content, 1000);
            if (Is选项存在_模糊(content))
            {
                string js_select = @"getElementByText2('li','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_JS(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }
        private bool 填写内容并选取_Class(string class_id,int index, string content)
        {
            string js = @$"document.getElementsByClassName('{class_id}')[0].getElementsByTagName('input')[{index}];";
            点击元素_输入(js, content, 1000);
            if (Is选项存在(content))
            {
                string js_select = @"getElementByText('li','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_左键(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }
        private bool 填写内容并选取_Class_品牌(string class_id, int index, string content)
        {
            string js = @$"document.getElementsByClassName('{class_id}')[0].getElementsByTagName('input')[{index}];";
            string input_text = content.Split('-')[0];
            点击元素_输入(js, input_text, 1000);
            if (Is选项存在(content))
            {
                string js_select = @"getElementByText('li','{0}')";
                string js3 = string.Format(js_select, content);
                点击元素_左键(js3, wordWaitTime);
            }
            else
            {
                return false;
            }
            return true;
        }

        private bool 点击并填写内容_Class(string class_id, int index, string content)
        {
            string js = @$"document.getElementsByClassName('{class_id}')[0].getElementsByTagName('input')[{index}];";
            点击元素_输入(js, content, 1000);            
            return true;
        }
        private bool 填写内容(string id, string content)
        {
            string js_base = @"var ele=document.getElementById('{0}').getElementsByTagName('input')[0];setInputValue(ele,'{1}');";
            string js = string.Format(js_base, id, content);
            ExecuteScriptAndWaitAsync(js, 1000);
            return true;
        }
        private void 点击内容(string id)
        {
            string js_base = @"document.getElementById('{0}').getElementsByTagName('input')[0]";
            string js = string.Format(js_base, id);
            点击元素_左键(js);
        }
        private bool Is选项存在(string content)
        {
            string js_check = @" (function(){
                return getElementByText('li','"+ content+@"')!=null;
            })() ";
            string result = EvaluateScriptAsync(js_check);
            if (result == "False")
            {
                return false;
            }
            return true;
        }
        private bool Is选项存在_DIV(string content)
        {
            string js_check = @" (function(){
                return getElementByText('div','" + content + @"')!=null;
            })() ";
            string result = EvaluateScriptAsync(js_check);
            if (result == "False")
            {
                return false;
            }
            return true;
        }
        private bool Is选项存在_模糊(string content)
        {
            string js_check = @" (function(){
                return getElementByText2('li','" + content + @"')!=null;
            })() ";
            string result = EvaluateScriptAsync(js_check);
            if (result == "False")
            {
                return false;
            }
            return true;
        }
        private void 选取( string content)
        {
            string js_base2 = @"getElementByText('li','{0}')";
            string js2 = string.Format(js_base2, content);
            点击元素_左键(js2);
        }
        private void 等待上传执行完毕(List<string> img_path) 
        {
            List<string> fileNames = img_path.Select(n => Path.GetFileNameWithoutExtension(n)).ToList();
            for (int i = 0; i < 10; i++)
            {
                string result = EvaluateScriptAsync(JavaScriptString.TEMU_判断是否上传完毕JS);
                if (!fileNames.Contains(result))
                {
                    WaitWebBrowserAsync(500);                   
                }
                else
                {                   
                    return;
                }
            }
        }
        private void 选择上传的图片(List<string> img_path)
        {
            List<string> fileNames = img_path.Select(n => Path.GetFileNameWithoutExtension(n)).ToList();
            foreach (string item in fileNames)
            {
                string js = $@"getElementByText('div','{item}').click()";
                ExecuteScriptAndWaitAsync(js,500);
            }
            return;
        }
        private bool 判断是否重复上传()
        {
            for (int i = 0; i < 6; i++)
            {
                string result = EvaluateScriptAsync(JavaScriptString.TEMU_判断是否重复上传JS);
                if (result == "在列表中查看")
                {
                    WaitWebBrowserAsync(500);
                    return true;
                }
                else
                {
                    WaitWebBrowserAsync(500);
                }
            }
            return false;
        }


    }
}
